<?php
	session_start();
	$_SESSION['uid']=1;
	$_SESSION['username']='李四99';
	include "smarty.php";
	header("Content-type:text/html;charset=utf8");
	// echo "<pre>";
	// print_r($smarty);
	$smarty->left_delimiter= "{hd:";
    $smarty->right_delimiter= "}";
	$smarty->caching=false;//开启缓存
	$smarty->cache_lifetime=600;
	if(!$smarty->is_cached("cache.html",$_SERVER['REQUEST_URI'])){
		echo time();
		$db= mysql_connect("127.0.0.1","root","");
		mysql_select_db("c7");
		mysql_query("set names utf8");
		//处理分页
		$result = mysql_query("select count(id) as total from news");
		$row = mysql_fetch_assoc($result);
		$total = $row['total'];//总页数
		$page_one_rows=6;//每页显示条数
		$page_self = isset($_GET['page'])?(int)$_GET['page']:1;
		$page_nums = ceil($total/$page_one_rows);//总页数
		$page_str='';
		for($i=1;$i<=$page_nums;$i++){
			if($i==$page_self){
				$page_str.="<span>$i</span>";
				continue;
			}
			$page_str.="<a href='?page=$i'>$i</a>";
		}
		$limit =  " limit ".($page_self-1)*$page_one_rows.','.$page_one_rows;
		$smarty->assign('page',$page_str);
		$result = mysql_query("select * from news $limit");
		$rows= array();
		while($row =mysql_fetch_assoc($result)){
			$rows[]=$row;
		}
		$smarty->assign("rows",$rows);
	}

	$smarty->register_block("nocache", "nocache", false); 
	function nocache($params, $content, &$smarty) {
		return $content; 
	}
	$smarty->assign("time",time());
	$smarty->display("cache.html",$_SERVER['REQUEST_URI']);










?>